package com.addedstuff;

import java.util.ArrayList;
import java.util.Random;

import brianchen.util;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class weakarenastarter extends Block 
{
//weak version of arenastarter
	public void registerIcons(IconRegister iconReg)
	{
	    blockIcon = iconReg.registerIcon("Brianmodbase:brianweakarenastarter.fw");
	}
	public weakarenastarter(int par1) 
	{
		 super(par1,Material.dragonEgg);
		 
		 setCreativeTab(CreativeTabs.tabBlock);
		// TODO Auto-generated constructor stub
	}
	public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
	{
		activated=true;//			   x     y     z
		par1World.scheduleBlockUpdate(par2, par3, par4 , blockID, 1);
	    return false;
	}
    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) 
    {
    	if(activated)
    	{
    		if (maxCreatures > creaturelist.size())
    		{
    			if (maxNumSkeleton > numSkeletonCreated)
    			{
    				EntitySkeleton Skeleton= new EntitySkeleton(par1World);//x,y,z
    				Vec3 vec = util.placeInRandomDirection(par2, par3, par4, 2);
    				Skeleton.setPosition(vec.xCoord, vec.yCoord, vec.zCoord);
     				Skeleton.setCurrentItemOrArmor(0, new ItemStack(Item.swordDiamond));
    				Skeleton.setCurrentItemOrArmor(1, new ItemStack(Item.bootsDiamond));
     				Skeleton.setCurrentItemOrArmor(2, new ItemStack(Item.legsDiamond));
     				Skeleton.setCurrentItemOrArmor(3, new ItemStack(Item.plateDiamond));
     				Skeleton.setCurrentItemOrArmor(3, new ItemStack(Item.helmetDiamond));
     				par1World.spawnEntityInWorld(Skeleton);
    				numSkeletonCreated++;
    				creaturelist.add(Skeleton);
    			}
    			else if (maxNumZombie > numZombieCreated)
    			{
    				EntityZombie Zombie= new EntityZombie(par1World);//x,y,z
    				Vec3 vec = util.placeInRandomDirection(par2, par3, par4, 2);
    				Zombie.setPosition(vec.xCoord, vec.yCoord, vec.zCoord);
    				par1World.spawnEntityInWorld(Zombie);
    				numZombieCreated++;
    				creaturelist.add(Zombie);
    			}
    			else if (maxNumSpider > numSpiderCreated)
    			{
    				EntitySpider Spider = new EntitySpider(par1World);//x,y,z
    				Vec3 vec = util.placeInRandomDirection(par2, par3, par4, 2);
    				Spider.setPosition(vec.xCoord, vec.yCoord, vec.zCoord);
    				par1World.spawnEntityInWorld(Spider);
    				numSpiderCreated++;
    				creaturelist.add(Spider);
    			}
    			else 
    			{
    				won = true;
    				activated = false;
    			}
    		for (int i = creaturelist.size()-1;i >=0;i--)
    		{
    			if (creaturelist.get(i).isDead)
    			{
    				creaturelist.remove(i);
    			}
    		}
    		
    		par1World.scheduleBlockUpdate(par2, par3, par4 , blockID, 60);
    		
    		}
    		
    	}
    	else if (won)
    	{
    		if (this.wonTicks >= 0 && this.wonTicks <= 20)
            {
                float f = (float)(Math.random() - 0.5F * 8.0);
                float f1 = (float)(Math.random() - 0.5F * 8.0);
                float f2 = (float)(Math.random() - 0.5F * 8.0);
                par1World.spawnParticle("hugeexplosion", par2	 + (double)f, par3 + 2.0D + (double)f1, par4 + (double)f2, 0.0D, 0.0D, 0.0D);
                
            }
    		wonTicks++;
    	}
    }
    
    private boolean won = false;
    private int wonTicks = 0;
    private boolean activated = false;
    private int maxCreatures = 12;
    private int numSkeletonCreated = 0;
    private int numZombieCreated = 0;
    private int numSpiderCreated = 0;
    private int maxNumSpider = 10;
    private int maxNumZombie = 10;
    private int maxNumSkeleton = 10;
    private ArrayList<EntityLiving> creaturelist=new ArrayList();
    

}